﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Nancy;
using PlatWL.Models;
using Nancy.ModelBinding;
using Nancy.Security;
using PlatWL.Services.Services;
using PlatWL.Data;

namespace PlatWL.Modules.Admin
{
    public class AdvertModule : AdminModule
    {
        public AdvertModule(AdvertManage service) : base("advert")
        {
            this.RequiresAuthentication();
            //列表
            Get["/list/{client?}"] = p =>
            {
                string client = this.Request.Query["client"];

                string searchkey = this.Request.Query["searchkey"];

                string type1 = this.Request.Query["type1"];
                string type2 = this.Request.Query["type2"];
                string isself = this.Request.Query["IsShelf"];

                service.GetList(ref msg, Client, page, searchkey, type1 ?? "", isself ?? "", client ?? "");
                return this.Response.AsJson(msg);
            };

            //广告model
            Get["/model/{id:int}"] = p =>
            {
                service.GetModel(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };

            Post["/add"] = p =>
            {
                var ad = this.Bind<pt_info_advert>();
                service.AddModel(ref msg, Client, ad, auth_user);
                return this.Response.AsJson(msg);
            };

            Get["/del/{id:int}"] = p =>
            {
                service.DelModel(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };
            //上下架
            Get["/shelf/{id:int}"] = p =>
            {
                service.SetShelf(ref msg, Client, p.id);
                return this.Response.AsJson(msg);
            };

        }
    }
}